<%-- 
    Document   : search
    Created on : Oct 31, 2011, 3:04:49 AM
    Author     : northpole
--%>
<%@page import="javax.naming.spi.DirStateFactory.Result"%>
<%@page import="java.util.ArrayList"%>
<%@page import="user.User" contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
          <link type="text/css" rel="stylesheet" href="sidebar.css" media="screen" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <%User userInfo=null;
   userInfo=new User();

    String paramsUser=request.getParameter("username"),
        paramsDate=request.getParameter("date"),
        paramsName=request.getParameter("name"),
        paramsSurname=request.getParameter("surname"),
        paramsExcl=request.getParameter("exclusive");

ArrayList paramsInter=new ArrayList();
int j=0;
for(int i=0;i<10;i++)
{
    String interest="interests"+i;
    if(request.getParameter("interests"+i)!=null
    &&!request.getParameter("interests"+i).isEmpty())
    {paramsInter.add(request.getParameter("interests"+i));;}else j++;
   // else
   //{     response.sendRedirect("ErrorPage.html?i="+i);return;}
}

ArrayList <String>result=new ArrayList();
boolean and=false,or=false;

if(paramsExcl!=null)
{    if(paramsExcl.equals("and"))
        and=true;
}
else
or=true;


if(
        (
        (paramsUser!=null&&!paramsUser.isEmpty())||
        (paramsDate!=null&&!paramsDate.isEmpty())||
        (paramsName!=null&&!paramsName.isEmpty())||
        (paramsSurname!=null&&!paramsSurname.isEmpty())||
        (paramsInter!=null&&!paramsInter.isEmpty())
        )
        )
{  
        result=userInfo.getMisc().search(paramsUser, paramsInter, paramsDate, paramsName, paramsSurname,and,or);
     
}
%>
    </head>
<body>

     <div style="z-index: 100%;">
        <a href="index.jsp" >Go Back
<img src="imadge/pixel-mario.gif" alt="HTML tutorial" width="32" height="32" />
</a>
        </div>
 <div id="text" >
    <li>
        
<%
//out.print(paramsInter.toString());
//out.print(result.toString()+j);
if(result!=null&&!result.isEmpty())
{%>Search Found:
         <%
    for(int i=0;i<result.size();i++)
{%>
<ul><a href="profile.jsp?username=<%out.print(result.get(i));%>">
        <%out.print(result.get(i));%></a></ul><%
}
 %>


<%}
    %>
    </li>
      <%if(result!=null&&!result.isEmpty()){%>
        Find Moar?<%}
        else
            out.print("Please Fill at Least One of The text boxes below");
          %>
    <form name="SuperSearch" action="search.jsp" method="get">
        <li>
          <ul>      Username:      <input type="text" name="username" size="20"/><br>
          </ul><ul>      Date Of Birth: <input type="text" name="date" size="11"/><br>
          </ul><ul> Name:          <input type="text" name="name" size="20"/><br>
          </ul><ul>  Surname:       <input type="text" name="surname" size="11"/><br>
          </ul> <ul>    Interests:
                <%for(int i=0;i<10;i++)
                {out.print("<input type=\"text\" name=\"interests"+i+"\" size=\"11\"/>");
                    if(i%2==0)
                        out.print("</ul><ul>");
}%>
    <br>               
                        <input type="radio" name="exclusive" value="and" /> logical and<br />
                        <input type="radio" name="exclusive" value="or" /> logical or
                        <input type="submit" value="Send"/>
                        </li>
</form>



    </div>
</body>
</html>
